package com.scsj.supermarket.view.activity.walletmodel;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.alibaba.fastjson.JSONObject;
import com.jakewharton.rxbinding.view.RxView;
import com.scsj.supermarket.R;
import com.scsj.supermarket.base.RechargeBase;
import com.scsj.supermarket.bean.RechargeBean;
import com.scsj.supermarket.presenter.RechargePresenter;
import com.scsj.supermarket.utils.ToastMiddleUtils;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.vondear.rxtools.module.alipay.AliPayModel;
import com.vondear.rxtools.module.alipay.AliPayTools;
import com.vondear.rxtools.view.RxToast;

import java.util.concurrent.TimeUnit;

import es.dmoral.toasty.Toasty;
import okhttp3.RequestBody;
import rx.functions.Action1;

import static android.provider.UserDictionary.Words.APP_ID;

/**
 * 充值
 */
public class MineRechargeActivity extends BaseActivity implements RechargeBase.IView,View.OnClickListener {

    private EditText mMoneyEdt;
    private RelativeLayout mPayZhifubaoRl;
    private RelativeLayout mPayWeixinRl;
    private RechargePresenter presenter;

    private String mPrivateKey,mWXID,mSellerID,mOrderId;


    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_mine_recharge);

        presenter = new RechargePresenter(this);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("amount","151");
        jsonObject.put("wechatType","4");
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonObject.toString());
        presenter.deliverData(body);

        initToolbar();
        setToolbarTitle("充值");
        hasBack(true);

        initView();
    }

    @Override
    protected void initView() {
        mMoneyEdt = (EditText) findViewById(R.id.money_edt);
        mPayZhifubaoRl = (RelativeLayout) findViewById(R.id.pay_zhifubao_rl2);
        mPayWeixinRl = (RelativeLayout) findViewById(R.id.pay_weixin_rl2);
        mPayZhifubaoRl.setOnClickListener(this);
        mPayWeixinRl.setOnClickListener(this);
    }

    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.pay_zhifubao_rl2:
//                AliPayTools.aliPay(mContext,
//                        APP_ID,//支付宝分配的APP_ID
//                        isRSA2,//是否是 RSA2 加密
//                        RSA_PRIVATE,// RSA 或 RSA2 字符串
//                        new AliPayModel(order_id,//订单ID (唯一)
//                                money,//价格
//                                name,//商品名称
//                                detail),//商品描述详情 (用于显示在 支付宝 的交易记录里)
//                        new onRequestListener() {
//                            @Override
//                            public void onSuccess(String s) {
//                                RxToast.success("支付成功");
//                            }
//
//                            @Override
//                            public void onError(String s) {
//                                RxToast.error("支付失败");
//                            }
//                        });
                break;
            case R.id.pay_weixin_rl2:
//                WechatPayApp(mContext,
//                        app_id, //微信分配的APP_ID
//                        partner_id, //微信分配的 PARTNER_ID (商户ID)
//                        wx_private_key, //微信分配的 PRIVATE_KEY (私钥)
//                        prepay_id, //订单ID (唯一)
//                        new onRequestListener() {
//                            @Override
//                            public void onSuccess(String s) {
//                            }
//
//                            @Override
//                            public void onError(String s) {
//                            }
//                        });
                break;
        }
    }

    @Override
    public void showSuccessMsg(String s, RechargeBean rechargeBean) {
        Toasty.info(MineRechargeActivity.this,s).show();
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.info(MineRechargeActivity.this,s).show();
    }
}
